#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <bitset>
#include <utility>
using namespace std;

#define mm(a, n) memset(a, n, sizeof a)
#define mk(a, b) make_pair(a, b)

const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

const int N = 21;

int n;
int l[N], r[N];
bool st[N];
int last_node;

bool check(int u) {
    bool flag = false;
    queue<int> q;
    q.push(u);
    last_node = u;
    while (q.size())
    {   
        int root = q.front(); q.pop();
        if (l[root] != -1) {
            if (!flag) q.push(l[root]), last_node = l[root];
            else return false;
        }
        else flag = true; 

        if (r[root] != -1) {
            if (!flag) q.push(r[root]), last_node = r[root];
            else return false;
        } else flag = true;
    }
    return true;
}

inline void solution() {
    mm(l, -1);
    mm(r, -1);
    mm(st, false);
    cin >> n;
    for (int i = 0; i < n; i ++ ) {
        string a, b;
        cin >> a >> b;
        if (a != "-") l[i] = stoi(a), st[l[i]] = true;
        if (b != "-") r[i] = stoi(b), st[r[i]] = true;
    }

    int root;
    for (int i = 0; i < n; i ++ ) 
        if (!st[i]) 
            root = i;
    if (check(root)) 
        printf("YES %d\n", last_node);
    else 
        printf("NO %d\n", root);

}

int main() {
    freopen("input.txt", "r", stdin);
    quickread();
    solution();
    return 0;
}